// @Title messageControl.go
// @Description:
// @Author 姓名编写
// @Date 2024/3/4
// @Update 姓名编写 2024/3/4

/**************************************************
*Copyright(C).2016-2024,瀚辰光翼⽣物科技有限公司
*文件名：messageControl.go
*内容简述：*
*文件历史：
author 姓名编写 创建 2024/3/4
**************************************************/
package controller

import (
	"cec-server/app/common/process"
	"cec-server/app/common/resp"
	"cec-server/app/model"
	"fmt"
	"github.com/gin-gonic/gin"
)

type Message struct {
}

// SendMessage
// @Summary  发送消息接口,组装参数，直接发到Kafka
// @Description SendMessage
// @Param receiver body model.SendRequest true "接收者id"
// @Success 200 {object} resp.JsonStruct
// @Failure 400 {object} resp.JsonStruct
// @router /message/send [post]
func (m Message) SendMessage(context *gin.Context) {

	var sendRequest model.SendRequest
	if err := context.Bind(&sendRequest); err != nil {
		resp.ReturnError(context, 400, err.Error())
		return
	}
	fmt.Println(sendRequest)
	sendRequest.MessageParam.Receiver = "123456"

	//todo 这里发送消息到Kafka
	sendTaskModel := model.SendTaskModel{
		MessageTemplateId: sendRequest.MessageTemplateId,
		MessageParamList: []model.MessageParam{
			{
				Variables: sendRequest.MessageParam.Variables,
				Extra:     sendRequest.MessageParam.Extra,
				Receiver:  sendRequest.MessageParam.Receiver,
			},
		},
	}

	err := process.SendProcess.RunProcess(context, &sendTaskModel)
	if err != nil {
		return
	}

	//send.GetHandler()

	//send.SendMessageUsingDI(send.MailSend{}, messageParam)

	resp.ReutrnSuccess(context, 200, "success", "hello message", 1)
	return
}
